/*
 * MenuBar.java
 * 
 * Created on Aug 18, 2007, 7:58:48 PM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.usixml.model.client.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author htmfilho
 */
public class MenuBar extends JMenuBar implements ActionListener {
    
    private JMenu mnFile;
    private JMenuItem mniOpen;
    private JMenuItem mniExit;
    
    public MenuBar() {
        initComponent();
    }

    private void initComponent() {
        mnFile = new JMenu("File");
        mnFile.setMnemonic(KeyEvent.VK_F);
        
        mniOpen = new JMenuItem("Open...");
        mniOpen.setMnemonic(KeyEvent.VK_O);
        mnFile.add(mniOpen);
        
        mnFile.addSeparator();
        
        mniExit = new JMenuItem("Exit");
        mniExit.setMnemonic(KeyEvent.VK_X);
        mniExit.addActionListener(this);
        mnFile.add(mniExit);
        
        this.add(mnFile);
    }
    
    public void setOpenListener(ActionListener listener) {
        mniOpen.addActionListener(listener);
    }

    public void actionPerformed(ActionEvent e) {
        Object object = e.getSource();
        
        if(object == mniExit) {
            System.exit(0);
        }
    }
}